package com.qc.blogsystemplus.mapper;

import com.qc.blogsystemplus.bean.UserBean;
import com.qc.blogsystemplus.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UserMapper {

    @Select("SELECT `user`.id,username,`password`,nickname,register_time,phone,ban,role.role_name,city,email FROM `user`,role WHERE `user`.role_id = role.id AND username = #{username}")
    User getUser(String username);

    @Select("SELECT `user`.id,username,`password`,nickname,register_time,phone,ban,role.role_name,city,email FROM `user`,role WHERE `user`.role_id = role.id")
    List<User> getAllUser();

    @Insert("INSERT INTO `user` (username,`password`,register_time,nickname,email,phone,city,role_id) VALUES(#{username},#{password},#{register_time},#{nickname},#{email},\n" +
            "#{phone},#{city},#{role_id} \n" +
            ")")
    int addUser(UserBean userBean);

    @Update("UPDATE `user` SET username = #{username},`password` = #{password},nickname = #{nickname},email = #{email},phone= #{phone},city = #{city} WHERE username = #{username}")
    int updateUser(UserBean userBean);

    @Delete("DELETE FROM `user` WHERE username=#{username}")
    int delUser(String username);
}
